home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Columbia Kermit
/
kermit.zip
/
newsgroups
/
misc.19981211-19990422
/
000382_news@watsun.cc.columbia.edu _Fri Mar 19 11:45:32 1999.msg
< prev
next >
Wrap
Internet Message Format
|
2020-01-01
|
2KB
Return-Path: <news@watsun.cc.columbia.edu>
Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id LAA14134
for <kermit.misc@watsun.cc.columbia.edu>; Fri, 19 Mar 1999 11:45:31 -0500 (EST)
Received: (from news@localhost)
by newsmaster.cc.columbia.edu (8.8.5/8.8.5) id LAA20625
for kermit.misc@watsun.cc.columbia.edu; Fri, 19 Mar 1999 11:43:01 -0500 (EST)
X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
From: dn5006@my-dejanews.com
Subject: Associative Array in Kermit 95
Date: Fri, 19 Mar 1999 16:27:07 GMT
Organization: Deja News - The Leader in Internet Discussion
Message-ID: <7cttsc$47f$1@nnrp1.dejanews.com>
To: kermit.misc@watsun.cc.columbia.edu
Associative array is a very useful feature in scripting language, it enables
Perl, Tcl etc. the implementation of comlex data structures.
The following script demonstrates that associative array can also be crafted
in Kermit 95. The script counts the unique words in a regular english, french,
german, etc. text file.
open read testfile.txt
if fail end 1 Can't not open testfile.txt
assign \%n 0 ; init register
while true {
read \%l ; read each line
if fail break ; until the end of file
while > \flength(\%l) 0 {
assign \%w \fbreak(\%l,{ }) ; split on space
xif defined \m(\%w) { ; word already seen?
_assign \%w \feval(\m(\%w) + 1) ; incr count this word
} else {
_assign \%w 1 ; init count this word
increment \%n ; next register
_assign \%n \%w ; register this word
}
assign \%l \fltrim(\fright(\%l,\feval(\flength(\%l) - \flength
(\%w)))) ; shift to next word
}
}
for \%k 1 \%n 1 {
assign \%w \m(\%k) ; get word from register
echo <\m(\%w)> \%w ; display occurences
}
This approach avoids the use of array which has to be declared in advance.
The script does not take into account the non alphanumeric characters.
Dat Nguyen
Airline Telecommunications and Information Services
770 Sherbrooke West
Montreal, Quebec
Canada H3A 1G1
Email dat.nguyen&sita.int
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own